package com.jiutong.meipenggang.http.present;

import android.content.Context;

import com.jiutong.meipenggang.common.Constants;
import com.jiutong.meipenggang.entity.HomeHongBaoBean;
import com.jiutong.meipenggang.entity.HongBaoBean;
import com.jiutong.meipenggang.entity.MeiLiCaiBean;
import com.jiutong.meipenggang.http.model.interfaces.HongBaoBiz;
import com.jiutong.meipenggang.http.model.interfaces.RepaymentPlanBiz;
import com.jiutong.meipenggang.http.model.requests.MeiLiCaiFragmentRequest;
import com.jiutong.meipenggang.http.subscribers.ProgressSubscriber;
import com.jiutong.meipenggang.http.subscribers.SubscriberOnNextListener;
import com.jiutong.meipenggang.utils.SpConfig;

import java.util.HashMap;

import rx.Subscriber;

/**
 * @author Veken
 * @date on 2017/12/19 11:32
 * @describe
 */

public class HongBaoPresent {

    private MeiLiCaiFragmentRequest meiLiCaiFragmentRequest;
    private Context mContext;
    private HongBaoBiz hongBaoBiz;

    public HongBaoPresent(Context mContext, HongBaoBiz hongBaoBiz) {
        this.mContext = mContext;
        this.hongBaoBiz = hongBaoBiz;
        meiLiCaiFragmentRequest = new MeiLiCaiFragmentRequest();
    }

    /**
     * 获取投资页选择红包信息
     */
    public void getHongBaoInfo(String birId){
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<HongBaoBean>() {
            @Override
            public void onNext(HongBaoBean object) {
                hongBaoBiz.onSuccess(object);
            }

            @Override
            public void onError(Throwable e) {
                hongBaoBiz.onError(e);
            }
        };
        HashMap<String,Object> fieldMap = new HashMap<>();
        fieldMap.put("OPT",58);
        fieldMap.put("bidId",birId);
        fieldMap.put("id", SpConfig.getInstance().getString(Constants.ID));
        fieldMap.put("token",SpConfig.getInstance().getString(Constants.TOKEN));
        meiLiCaiFragmentRequest.getHongBaoInfo(new ProgressSubscriber(onNextListener,mContext),fieldMap);
    }

    /**
     * 获取首页红包信息
     */
    public void getHomeHongBaoInfo(String type){
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<HomeHongBaoBean>() {
            @Override
            public void onNext(HomeHongBaoBean object) {
                hongBaoBiz.onSuccess(object);
            }

            @Override
            public void onError(Throwable e) {
                hongBaoBiz.onError(e);
            }
        };

        HashMap<String,Object> fieldMap = new HashMap<>();
        fieldMap.put("OPT",26);
        fieldMap.put("id",SpConfig.getInstance().getString(Constants.ID));
        fieldMap.put("token",SpConfig.getInstance().getString(Constants.TOKEN));
        fieldMap.put("redState",type);
        meiLiCaiFragmentRequest.getHomeHongBaoInfo(new ProgressSubscriber(onNextListener,mContext),fieldMap);
    }
}
